package cn.tedu.analyse.service.impl;


import cn.tedu.analyse.dao.mapper.CommentsMapper;
import cn.tedu.analyse.pojo.entity.Comments;
import cn.tedu.analyse.pojo.param.CommentsParam;
import cn.tedu.analyse.pojo.vo.CommentsVO;
import cn.tedu.analyse.service.CommentsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class CommentsServiceImpl implements CommentsService {
    @Autowired
    private CommentsMapper commentsMapper;



    @Override
    public void createComment(CommentsParam commentsParam) {
        log.debug("创建评论，参数：{}", commentsParam);
        Comments comments = new Comments();

        comments.setArticleId(commentsParam.getArticleId());
        comments.setContent(commentsParam.getContent());
        comments.setUserId(commentsParam.getUserId());
        comments.setParentId(commentsParam.getParentId());
        comments.setLevel(commentsParam.getLevel());
        comments.setIsTopLevel(commentsParam.getIsTopLevel());
        comments.setCreatedAt(new Date());

        commentsMapper.createComment(comments);

    }

    @Override
    public List<CommentsVO> listComments(Long articleId) {
        log.debug("获取评论列表，参数：{}", articleId);
        return commentsMapper.listComments(articleId);
    }

    @Override
    public void deleteComment(Long commentId) {
        log.debug("删除评论，参数：{}", commentId);
        commentsMapper.deleteComment(commentId);
    }
}
